package com.lantosec.hmrp.core.kit;

import com.lantosec.hmrp.core.exception.AppException;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

public class Auth {
    public static final String SESSION_USERNAME = "username";
    public static final String SESSION_NICKNAME = "nickname";
    public static final String SESSION_ROLES = "roles";
    public static final String SESSION_DEPT_LIST = "depts";
    public static final String SESSION_DEPT = "dept";

    public static Session getSession(){
        return SecurityUtils.getSubject().getSession();
    }

    /**获取当前登录的用户名
     * @return
     */
    public static String getUsername(){
        try{
            return SecurityUtils.getSubject().getPrincipal().toString();
        }catch(NullPointerException e){
            throw new AppException("用户未登录");
        }
    }

    /**获取当前登录的姓名
     * @return
     */
    public static String getName(){
        return SESSION_NICKNAME;
    }

    /**获取当前登录用户的角色编码
     * @return
     */
    public static String getRnumbers(){
        return SESSION_ROLES;
    }

    /**获取用户的最高组织机构权限集合
     * @return
     */
    public static String getDEPARTMENT_IDS(){
        return SESSION_DEPT_LIST;
    }

    /**获取用户的最高组织机构权限
     * @return
     */
    public static String getDEPARTMENT_ID(){
        return SESSION_DEPT;
    }
}
